/*
 * @Author: ls
 * @Date: 2021-11-24 17:19:24
 * @LastEditTime: 2021-11-25 10:25:35
 * @LastEditors: ls
 * @Description: HelloWorld
 * @FilePath: \demo\assets\Script\HelloWorld.ts
 */

import OpenImageFile from './OpenImageFile';

const { ccclass, property } = cc._decorator;

@ccclass
export default class HelloWorld extends cc.Component {
	@property(cc.Sprite)
	content: cc.Sprite = null;

	onCallBack() {
		OpenImageFile.openFile(this.setContent.bind(this));
	}

	/**
	 * 设置图片
	 * @param strImg
	 */
	setContent(strImg) {
		let img = new Image();
		img.src = strImg;

		let texture2D = new cc.Texture2D();
		texture2D.initWithElement(img);

		let spriteFrame = new cc.SpriteFrame(texture2D);
		this.content.spriteFrame = spriteFrame;
	}
}
